﻿using BootstrapBlazor.Components;
using BPM.Web.Shared.Data;
using BPM.Web.Shared.Dependencies;
using BPM.Web.Shared.Extensions;
namespace BPM.Web.Shared.Service;

[Scoped(typeof(ISysRoleService))]
public class SysRoleService : BaseService, ISysRoleService
{
    private readonly IRoleClient _client;
    public SysRoleService(IRoleClient client, ToastService toast) : base(toast)
        => _client = client;

    public Task<QueryData<SysRole>> PageAsync(RolePageInput input)
        => QueryAsync(_client.PageAsync(input));

    public Task<List<RoleOutput>?> DropDownAsync()
        => QueryAsync<List<RoleOutput>>(_client.DropDownAsync());

    public Task<bool> AddAsync(SysRole input)
        => ExecuteAsync(_client.AddAsync(input.Adapt<AddRoleInput>()));

    public Task<bool> DeleteAsync(IEnumerable<SysRole> input)
        => DeleteAsync(input.Adapts<SysRole, DeleteRoleInput>().Select(x => _client.DeleteAsync(x)));

    public Task<bool> EditAsync(SysRole input)
        => ExecuteAsync(_client.EditAsync(input.Adapt<UpdateRoleInput>()));

    public Task<SysRole?> DetailAsync(QueryRoleInput input)
        => QueryAsync(_client.DetailAsync(input));
}

